# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=dbus-c++
_srcname="lib${_realname}"
_upstream="dbus-cplusplus"
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.9.0
pkgrel=1
pkgdesc="A C++ API for D-BUS (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://dbus-cplusplus.sourceforge.net/"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-dbus")
source=("${_realname}-${pkgver}.tar.gz"::"https://sourceforge.net/projects/${_upstream}/files/${_realname}/${pkgver}/${_srcname}-${pkgver}.tar.gz"
        'gcc47.patch'
        'disable-threading.patch'
        'fix-writechar.patch'
        'dbus-c++-0.9.0-mingw.patch')
sha256sums=('bc11ac297b3cb010be904c72789695543ee3fdf3d75cdc8225fd371385af4e61'
            '9d504faf769026dcaabca94c7645373fcadf43ef93c8263c6a85e905798f07c9'
            '38730ee73fe4de320fceab6619579b55861b6b8e0f6d8069a9ddf3d1ad1266c0'
            '34ada5bf31918c63558d0fb3fff63e0f1596f25082ff22e84117927ad7236fce'
            'e015d31d7ab0107046daedcf34195d41ac99fa97453f05953cfceee70dd09f67')

prepare() {
  cd ${srcdir}/${_srcname}-${pkgver}
  patch -Np0 -i "${srcdir}/gcc47.patch"
  patch -Np1 -i "${srcdir}/disable-threading.patch"
  patch -Np1 -i "${srcdir}/fix-writechar.patch"
  patch -Np1 -i "${srcdir}/dbus-c++-0.9.0-mingw.patch"
  autoreconf -vi
}

build() {
  export LDFLAGS+=" -lexpat -lpthread -lws2_32" # -lpthread needed for i686
  export CPPFLAGS+=" -D_WIN32_WINNT=0x600" # needed to build with winsock2.h
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_srcname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --disable-ecore \
    --disable-glib \
    --disable-tests \
    --disable-examples

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
